package com.lm.liaoming.manager;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;

import android.view.View;

import com.longsh.optionframelibrary.OptionMaterialDialog;
import com.lm.liaoming.R;
import com.lm.liaoming.dialogtiplib.dialog_tip.TipLoadDialog;


/**
 * 韦敏敏
 */
public class DialogManager {

    private static TipLoadDialog tipLoadDialog;

    /**
     * 显示正在加载数据
     *
     * @param context
     */
    public static void showLoading(Context context) {
        dimissDialog();
        if (context==null) {
            return;
        }
        if (!((Activity)context).isFinishing()) {
            tipLoadDialog = new TipLoadDialog(context);
            tipLoadDialog.setNoShadowTheme()
                    .setMsgAndType("加载中", TipLoadDialog.ICON_TYPE_LOADING2)
                    .show();
        }

    }
    /**
     * 显示正在加载数据
     *
     * @param context
     */
    public static void showLoading(Context context,String msg) {
        dimissDialog();
        if (context==null) {
            return;
        }
        if (!((Activity)context).isFinishing()) {
            DialogManager.dimissDialog();
            tipLoadDialog = new TipLoadDialog(context);
            tipLoadDialog.setNoShadowTheme()
                    .setMsgAndType(msg, TipLoadDialog.ICON_TYPE_LOADING2)
                    .show();
        }

    }

    /**
     * 显示提示框
     * @param context
     */
    public static void showToath(Context context,String info) {
        if (context==null) {
            return;
        }
        if (!((Activity)context).isFinishing()) {
            tipLoadDialog = new TipLoadDialog(context);
            //设置无阴影主题
            tipLoadDialog.setNoShadowTheme().setMsgAndType(info, TipLoadDialog.ICON_TYPE_INFO).show();
        }

    }

    /**
     * 显示成功提示框
     * @param context
     */
    public static void showSuccessToath(Context context,String info) {
        if (context==null) {
            return;
        }
        if (!((Activity)context).isFinishing()) {
            tipLoadDialog = new TipLoadDialog(context);
            //设置无阴影主题
            tipLoadDialog.setNoShadowTheme().setMsgAndType(info, TipLoadDialog.ICON_TYPE_SUCCESS).show();
        }

    }

    /**
     * 显示成功提示框
     * @param context
     */
    public static void showErrorToath(Context context,String info) {
        if (context==null) {
            return;
        }
        if (!((Activity)context).isFinishing()) {
            tipLoadDialog = new TipLoadDialog(context);
            //设置无阴影主题
            tipLoadDialog.setNoShadowTheme().setMsgAndType(info, TipLoadDialog.ICON_TYPE_FAIL).show();
        }

    }

    /**
     * 关闭Dialog对话框
     */
    public static void dimissDialog() {
        if (tipLoadDialog!=null) {
            tipLoadDialog.dismiss();
        }
    }

    public interface OnDialogClickListener{
        void onClick();
        void onCancle();
    }

    public static void showDialog(final Context context, String title, String rtext, String ltext, final OnDialogClickListener onDialogClickListener) {
        final OptionMaterialDialog mMaterialDialog = new OptionMaterialDialog(context);
        mMaterialDialog
                .setMessage(title)
                .setMessageTextSize((float) 12)
                .setPositiveButton(rtext, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mMaterialDialog.dismiss();
                        onDialogClickListener.onClick();
                    }
                })
                .setPositiveButtonTextColor(R.color.colorPrimary)
                .setPositiveButtonTextSize(12)
                .setNegativeButton(ltext,
                        new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                mMaterialDialog.dismiss();
                                onDialogClickListener.onCancle();
                            }
                        })
                .setNegativeButtonTextSize(12)
                .setNegativeButtonTextColor(R.color.text_gray)
                .setCanceledOnTouchOutside(false)
                .setOnDismissListener(
                        new DialogInterface.OnDismissListener() {
                            @Override
                            public void onDismiss(DialogInterface dialog) {
                                //对话框消失后回调
//                                mMaterialDialog.dismiss();
                            }
                        })
                .show();
    }

}
